Your first action - Hello WebWorldTODO: finish this. The Codecom.acme.action.HelloWorld.java package com.acme.test; import com.opensymphony.xwork.ActionSupport; public class HelloWorld extends ActionSupport { private String message; public String execute() { message = "Hello, WebWorld!"; return SUCCESS; } public String getMessage() { return message; } } Let us create the view page. Create a file hello.jsp and place it under the YOUR_WEBAPP/WEB-INF/jsp directory: hello.jsp <%@ taglib prefix="ww" uri="/webwork" %> <html> <head> <title>Hello Page</title> </head> <body> WebWork says: <h1><ww:property value="message"/></h1> </body> </html> Edit the WEB-INF/classes/xwork.xml file as shown below, adding the helloWorld action and something called an interceptor to the default package. Read more: xwork.xml xwork.xml <!DOCTYPE xwork PUBLIC "-//OpenSymphony Group//XWork 1.0//EN" "http://www.opensymphony.com/xwork/xwork-1.0.dtd"> <xwork> <!-- Include webwork defaults (from WebWork JAR). --> <include file="webwork-default.xml"/> <package name="default" extends="webwork-default"> <default-interceptor-ref name="basicStack"/> <action name="helloWorld" class="com.acme.test.HelloWorld"> <result name="success">/WEB-INF/jsp/hello.jsp</result> </action> </package> </xwork> Go ahead and try it now: go to the url http://localhost:8080/YOUR_WEBAPP/helloWorld.action and see what happens. You should see a page that says "Hello, WebWorld!". How the code worksmThe above four files work together like this.
|